﻿using System;
using System.Drawing;
using System.Windows.Forms;

namespace SimpleTerminal.Render
{
	// class MyMenuRender : ToolStripProfessionalRenderer
	class MenuStripMenuFatRender : ToolStripSystemRenderer
	{

		protected override void OnRenderItemBackground(ToolStripItemRenderEventArgs e)
		{
			//base.OnRenderItemBackground(e);
			if (e.Item.Enabled && e.Item.Selected)
			{
				e.Graphics.FillRectangle(new SolidBrush(Color.Red),
					new Rectangle(0, 0, e.Item.Width, e.Item.Height));
			}
			else
			{
				e.Graphics.FillRectangle(new SolidBrush(Color.Red),
					new Rectangle(0, 0, e.Item.Width, e.Item.Height));
			}
		}

		protected override void OnRenderToolStripBackground(ToolStripRenderEventArgs e)
		{
			//   base.OnRenderToolStripBackground(e);
			//   e.Graphics.FillRectangle(new SolidBrush(Color.Red), e.AffectedBounds);
		}



		protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
		{
			if (e.ToolStrip is MenuStrip)
			{
				if (e.Item.Enabled && (e.Item.Selected || e.Item.Pressed))
				{
					using (SolidBrush solidBrush = new SolidBrush(Color.FromArgb(0x26, 0x75, 0xbf)))
					{
						e.Graphics.FillRectangle(solidBrush,
						new Rectangle(0, 0, e.Item.Width, e.Item.Height));
					}
				}
				else
				{
					using (SolidBrush solidBrush = new SolidBrush(e.ToolStrip.BackColor))
					{
						e.Graphics.FillRectangle(solidBrush,
												new Rectangle(0, 0, e.Item.Width, e.Item.Height));
					}
				}

			}
			else
			{
				if (e.Item.Enabled && e.Item.Selected)
				{
					e.Graphics.FillRectangle(SystemBrushes.ControlLight,
											   new Rectangle(0, 0, e.Item.Width, e.Item.Height));

				}
				else
				{
					using (SolidBrush solidBrush = new SolidBrush(Color.White))
					{
						e.Graphics.FillRectangle(solidBrush,
												new Rectangle(0, 0, e.Item.Width, e.Item.Height));
					}
				}

			}


		}
		/// <summary>
		/// 渲染菜单项的分隔线
		/// </summary>
		/// <param name="e"></param>
		protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
		{

			e.Graphics.DrawLine(new Pen(Color.FromArgb(200, 200, 200), 1), e.Item.Width / 2,
				5, e.Item.Width / 2, e.Item.Height - 5);
		}

		protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
		{

			if (e.Item.Selected || e.Item.Pressed)
			{
				if (e.ToolStrip is MenuStrip)
				{
					e.TextColor = Color.White;
                }
                else
                {
					e.TextColor = Color.Black;
				}
			}
			base.OnRenderItemText(e);
		}

		//  protected override 

		protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
		{
			if (!(e.ToolStrip is MenuStrip))
			{
				e.Graphics.FillRectangle(SystemBrushes.ControlLightLight, e.ConnectedArea);
				//e.Graphics.ExcludeClip(e.ConnectedArea);

				e.Graphics.DrawRectangle(Pens.Gray,
					e.AffectedBounds.X,
					e.AffectedBounds.Y,
					e.AffectedBounds.Width - 1,
					e.AffectedBounds.Height - 1
					);
			}

		}
	}
}
